<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 300px;
        height: 300px;
        background-color: #ccc;
      }
      p:nth-of-type(odd) {
        background-color: pink;
      }
      p:nth-of-type(even) {
        background-color: thistle;
      }
    </style>
  </head>
  <body>
    <div class="box" id="box"></div>
    <div class="text" id="text">
      <p id="p1" draggable="true">one</p>
      <p id="p2" draggable="true">two</p>
      <p id="p3" draggable="true">three</p>
    </div>
  </body>
  <script>
    window.onload = function () {
      var box = document.querySelector("#box");
      var father = document.querySelector("#text");
      var p1 = document.querySelector("#p1");
      var p2 = document.querySelector("#p2");
      var p3 = document.querySelector("#p3");
      var children = father.children;
      for (var i = 0; i < children.length; i++) {
        children[i].id.ondragstart = function (e) {
          e.dataTransfer.setData(`p${i + 1}`, children[i].id.innerHTML);
        };
      }
      //   p1.ondragstart = function (e) {
      //     e.dataTransfer.setData("p1", p1.innerHTML);
      //   };
      //   p2.ondragstart = function (e) {
      //     e.dataTransfer.setData("p2", p2.innerHTML);
      //   };
      //   p3.ondragstart = function (e) {
      //     e.dataTransfer.setData("p3", p3.innerHTML);
      //   };
      box.addEventListener("dragover", function (e) {
        e.preventDefault();
      });
      box.addEventListener("drop", function (e) {
        e.preventDefault();
        box.innerHTML += e.dataTransfer.getData("p1");
        box.innerHTML += e.dataTransfer.getData("p2");
        box.innerHTML += e.dataTransfer.getData("p3");
      });
    };
  </script>
</html>
